/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
* This is a pure interface class that defines an interface to the serial port
* Inherit this class if you want to make "general" serial port driver
* 
*/
#ifndef CSerialDriver_H_
#define CSerialDriver_H_

class CSerialDriver{
  public:
    CSerialDriver(){};
		virtual ~CSerialDriver(){};
		  
		/**
		 * Open the serial driver
		 * Opens the handle and sets the communication parameters
		 * @p serialport : The serial port name = "/dev/tty0" or "COM1" etc
		 * @p baudrate : the communication flow rate (speed).
		 * @p charsize : the character size (7,8 bits)
		 * @p parity   : 0=none, 1=odd, 2=even
		 * @p stopbits : the number of stop bits (1 or 2)
		 *
		 * @return true in success, false if failure
		 */
		virtual bool Open(const char *serialport, int baudrate,int dataBits,int parity, int stopBits)=0;
		
		/**
		* Close the driver 
		* @return true on success, else false  
		*/
		virtual bool Close()=0;
		
		/**
		* Clears the serial buffer
		* @return true on success, else false
		*/
		virtual bool Clear()=0;
		virtual bool ReadChar(unsigned char &c)=0;
		/**
		 * Read the data from the serial. 
		 * 
		 * @p *inbuf buffer that stores the input characthers (user must initialize)
		 * @p length the # of bytes of wanted to receive
		 *
		 * @return     -1 on timeout, else the number of bytes read. 
		 */
		 virtual int Read(char *inbuf, int length)=0;
		/**
		 * Writes data to serial
		 *
		 * @p data      data to be written
		 * @p length    the length of the data
		 * @return      true in success, else false
		 */
		virtual bool Write(char* data, int length)=0;

  
};
#endif
